<!DOCTYPE html>
<html lang="zxx">

<head>
    <title>注册</title>
    <!-- Meta tags -->
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <!-- //Meta tags -->
    <link rel="stylesheet" th:href="@{/css/style-login.css}" type="text/css" media="all" /><!-- Style-CSS -->
    <link th:href="@{/css/font-awesome.css}" rel="stylesheet"><!-- font-awesome-icons -->
</head>

<body>
<section class="w3l-form-36">
    <div class="form-36-mian section-gap" style="background: url('images/register-background.jpg'); background-size: cover">
        <div class="wrapper">
            <div class="form-inner-cont">
                <h3>Register now</h3>
                <form class="signin-form" id="userInfo">
                    <div class="form-input">
                        <span class="fa fa-user-o" aria-hidden="true"></span> <input type="text" name="username"
                                                                                     placeholder="Username" autocomplete="off" required />
                    </div>
                    <div class="form-input">
                        <span class="fa fa-key" aria-hidden="true"></span> <input type="password" name="password" autocomplete="off" placeholder="Password"

                                                                                 id="password" required />
                    </div>

                    <div class="form-input">
                        <span class="fa fa-key" aria-hidden="true"></span> <input type="password" autocomplete="off" placeholder="Confirm Password"
                                                                                  id="password_confirm" required />
                    </div>
                    <div class="login-remember d-grid">
                        <button class="btn theme-button">注册</button>
                    </div>
                </form>
                <p class="signup">已有帐号？点击<a th:href="@{/login}" class="signuplink">登录</a></p>
            </div>

            <!-- copyright -->
            <div class="copy-right">
                <p>Copyright &copy; 2020.Company name All rights reserved.</p>
            </div>
            <!-- //copyright -->
        </div>
    </div>
</section>

<!-- jQuery -->
<script th:src="@{js/jquery.min.js}"></script>
<!-- jQuery.form -->
<script th:src="@{js/jquery.form.min.js}"></script>
<!-- layer -->
<script th:src="@{js/layer.js}"></script>



<script>
    //登录表单提交
    $('#userInfo').submit(function(){
        var data = $("#userInfo").serialize();

        var options = {
            type : 'post',
            url  : 'http://localhost:80/api/global/register',
            data : data,
            beforeSubmit: function(){
                //判断密码是否合法
                var password = $("#password").val();
                var password_confirm = $("#password_confirm").val();



                if(password !== password_confirm){
                    layer.msg("两次密码输入不一致！");
                    return false
                }
            },
            success: function(result){
                ///注册出现错误
                if (result.code !== 0){
                    layer.msg(result.msg);
                    return ;
                }
                //注册成功，跳转到登陆界面
                window.location.href = "/client/login";
            },
        };

        $('#userInfo').ajaxSubmit(options);
        return false;
    });


</script>

</body>

</html>